package br.com.post.action;

import java.util.Date;
import java.util.List;

import br.com.post.model.State;
import br.com.post.model.Text;
import br.com.post.model.Topic;
import br.com.post.model.User;
import br.com.post.persistence.TextDao;
import br.com.post.persistence.TopicDao;

public class TextAction extends SuperAction {
	
	private Text text;
	private List<Topic> listTopic;
	private List<Text> listText;
	private TopicDao topicDao = TopicDao.getInstance();
	private TextDao textDao = TextDao.getInstance();
	private int id;
	
	/**
	 * Adiciona um novo texto no banco
	 * @return
	 */
	public String addText(){
		User user = (User) getRequest().getSession().getAttribute(USER_SESSION);
		State state = new State();
		state.setState_id(1);
		Date date = new Date();
		text.setText_date_register(date);
		text.setText_last_modified_date(date);
		text.setText_user_id(user);
		text.setText_state(state);
		textDao.createText(text);
		return SUCCESS;
	}
	

	public String loadAddText(){
		listTopic = topicDao.list();
		return SUCCESS;
	}
	
	public String listText(){
		listText = textDao.getList();
		return SUCCESS;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Text getText() {
		return text;
	}

	public void setText(Text text) {
		this.text = text;
	}



	public List<Topic> getListTopic() {
		return listTopic;
	}


	public void setListTopic(List<Topic> listTopic) {
		this.listTopic = listTopic;
	}


	public List<Text> getListText() {
		return listText;
	}


	public void setListText(List<Text> listText) {
		this.listText = listText;
	}


	public TopicDao getTopicDao() {
		return topicDao;
	}

	public void setTopicDao(TopicDao topicDao) {
		this.topicDao = topicDao;
	}

	public TextDao getTextDao() {
		return textDao;
	}

	public void setTextDao(TextDao textDao) {
		this.textDao = textDao;
	}
	
}
